home *** CD-ROM | disk | FTP | other *** search
/ BMUG PD-ROM A / PD-ROM A.iso / Programming / Programming Help / MacsBug / IntroToMacsBug next >
Encoding:
Text File  |  1992-01-05  |  34.7 KB  |  908 lines  |  [TEXT/EDIT]

  1. MacsBug with MultiFinder:  a practical example               by Carol Crews
  2.  
  3.  
  4. Introduction
  5.  
  6.     This document covers the basic MacsBug commands, and is intended for testers who have a 
  7. fairly good understanding of the Macintosh but are not necessarily programmers.  It is designed 
  8. both to develop a familiarity with MacsBug and to explain the changes in the heap structure which 
  9. are the result of the new MultiFinder environment.
  10.  
  11.  
  12.     There are five major sections:  the tutorial, the MacsBug command section, a discussion of 
  13. heaps in general, a discussion of the MultiFinder heap, and a list of information to include in bug 
  14. reports. In addition, there is a list of further MacsBug reference materials, and a chart of the 
  15. Macintosh character set (ASCII).  For those who have never used MacsBug before, the tutorial 
  16. will be helpful.  For others, the list of commands will serve as a more complete reference than 
  17. documents such as the MPW MacsBug section.  For those who are expert at MacsBug, the section 
  18. on the MultiFinder heap will be an introduction to the changes under MultiFinder.  Testers should 
  19. use the command list (section VII) as a starting point for deciding what to include in their bug 
  20. reports; their software engineers may have modifications to this list.
  21.  
  22.  
  23.     In order to follow this tutorial, you need:  MacsBug 5.5, System 4.2, Finder 6.0, 
  24. MultiFinder 1.0, MacWrite 4.6, and MacDraw 1.9.5.  If any of the terms in this document are 
  25. unfamiliar to you, check the glossary at the end of the document.  It is assumed that you are 
  26. experienced at working under MultiFinder.  
  27.  
  28.     
  29.  
  30.     To get into MacsBug, make sure you have both MacsBug and a programmer's switch 
  31. installed on your Mac.  Press the interrupt switch (the one at the very back; the one towards the 
  32. front will reboot the system), and you will drop into MacsBug.
  33.  
  34.  
  35. If you have any comments or recommendations for this document, please address them to me at 
  36. M/S 27AQ, x6677.
  37.  
  38.  
  39.  
  40.    I.  The goal        
  41.  
  42.     With a basic understanding of MacsBug, you will not only have a better idea of what has 
  43. happened when you crash during a testing session, but you will be better able to provide the software 
  44. engineers with information which may help them isolate and fix a bug.  The goal of the tutorial is to 
  45. provide you with a basic understanding of both MacsBug and the MultiFinder heap. 
  46.  
  47.  
  48.     The tutorial covers the most commonly used MacsBug commands, including:
  49.  
  50.             1.  PC
  51.  
  52.             2.  WH
  53.  
  54.             3.  DM
  55.  
  56.             4.  IL
  57.  
  58.             5.  HC
  59.  
  60.             6.  HT
  61.  
  62.             7.  HX
  63.  
  64.             8.  HD
  65.  
  66.             9.  CV
  67.  
  68.             10.  TD
  69.  
  70.             11.  DV
  71.  
  72.             12.  G
  73.  
  74.             13.  RB
  75.  
  76.             14.  ES
  77.  
  78.             15.  `
  79.  
  80.     In addition, it will explain how to examine the MultiFinder (Juggler) heap to find other 
  81. application heaps, and how to look at those heaps for more information.
  82.  
  83.  
  84.  
  85.     II.  The tutorial session 
  86.  
  87.         (Note:  this tutorial was written for an SE with 2.5 mgs.  Although you may not have this 
  88. configuration, you should still be able to follow all of the examples.  The important difference is that 
  89. the addresses listed in MacsBug will be different numbers; compare what you see on your screen to 
  90. what is listed in this document.)
  91.  
  92.  
  93.         1.  Boot your Mac with MultiFinder on.  Make sure that you have MacsBug 5.5 loaded in     
  94.         your system file.  (You can do this by pressing the programmer's interrupt switch and         
  95.     then typing DV, for Display Version.  Type G to return to the normal screen.)
  96.  
  97.         2.  Get info on the MacWrite application; set the size resource to 224K.
  98.  
  99.         3.  Get info on the MacDraw application; set the size resource to 192K.
  100.  
  101.         4.  Launch MacWrite.
  102.  
  103.         5.  Open the Alarm Clock.
  104.  
  105.         6.  Return to the Finder and launch MacDraw.
  106.  
  107.         7.  Press the programmer's interrupt switch to get into MacsBug.
  108.  
  109.  
  110.     Note:  you are now set up to follow the tutorial; the following sections are intended to 
  111.  
  112.  
  113.     III.  What to look at in MacsBug
  114.  
  115.         When you drop into MacsBug, you will see a display of registers that looks similar to this:
  116.  
  117.             
  118.  
  119. PC=00261C1C  SR=00002000  tSii   xnZvc      Ti=0000C4C0
  120.  
  121. D0=00000000  D1=00000210  D2=00000004  D3=00000001
  122.  
  123. D4=0000FFFF  D5=00000000  D6=001FDC9A  D7=00000000
  124.  
  125. A0=0026C0CE  A1=00261B1A  A2=00000000  A3=0040B5CC
  126.  
  127. A4=00000000  A5=0026E108  A6=001FCEAE  A7=001FCE8E
  128.  
  129. RA6 1FCE8E  001F CEF4 0026 5A2E A000 085A 0000 0000  .....&Z....Z....
  130.  
  131. RA7 1FCE8E  0000 0000 0026 1B96 0000 0000 0000 0001  .....&..........  
  132.  
  133.  
  134. 261C1C:   3002  0C400021              MOVE.W  D2,D0
  135.  
  136.             
  137.  
  138.   
  139.  
  140.     This is called the Total Display; you can get it onscreen whenever you are in 
  141. MacsBug by typing TD.  
  142.  
  143.     PC is the Program Counter; this register  contains the address of the next instruction 
  144. to be executed.  
  145.  
  146.     SR is the Status Register; it contains information about the status of the 68000 chip 
  147. and interrupt levels.
  148.  
  149.     A0, A1, A2, A3, A4, A5, A6, and A7 are 8 Address registers (lines 4 and 5 
  150. above), and D0, D1, D2, D3, D4, D5, D6, and D7 are 8 Data registers (lines 2 and 3 
  151. above).  Address registers are used to manipulate addresses, and data registers are used to 
  152. manipulate data.
  153.  
  154.  
  155.     As you can see above, the last line of the display starts with the address of the 
  156. program counter ("261C1C:"  refers to the same address as "PC=00261C1C", from the 
  157. first line of the display).  "MOVE.W" (at the end of this line) is the instruction which was 
  158. about to be carried out when you dropped into MacsBug.  Thus, you can see where the 
  159. program counter was (the address) and what it was going to do (the instruction MOVE.W).  
  160. You can include this information in your bug report, e.g. "PC=261C1C     MOVE.W  
  161. D2,D0".  This may help the engineers figure out what was happening when you crashed or 
  162. hung.
  163.  
  164.  
  165.     At this point, you can type a number of commands to get more information about 
  166. what was happening when you dropped into MacsBug:
  167.  
  168.  
  169. IV.  MacsBug Command Section
  170.  
  171.  
  172.             1.  PC  (program counter) 
  173.  
  174.     Although this information is usually shown in the total display (as demonstrated 
  175. above), it may not be displayed if you have crashed.  In order to get the information on the 
  176. program counter, just type PC.  MacsBug will then tell you where the program counter is 
  177. and what it was doing.  In this example, it says:
  178.  
  179.     261C1C:   3002  0C400021              MOVE.W  D2,D0
  180.  
  181.  
  182.             2.  WH PC (or WH; where pc)
  183.  
  184.     This command displays the location of the first named routine it finds, working back 
  185. through memory from the PC.  Ex:
  186.  
  187.     In RAM  Jug heap: 00261C1C
  188.  
  189. WH PC may not give the same address as PC; check both PC and WH PC and include the 
  190. results of both in your bug report.  If the current routine did not have a name, MacsBug 
  191. may go back a long way to find one; often, the first named routine it finds turns out to have 
  192. been the last ROM call made, which may have nothing to do with what was happening 
  193. when you crashed.  That's why it's important to include the info from both PC and WH in 
  194. your bug report.  (Note:  This command may crash MacsBug if heaps are in inconsistent 
  195. states.  You may want to do this command last.)
  196.  
  197.  
  198.             3.  DM 910 (display memory 910)
  199.  
  200.     Memory location 910 always contains the name of the currently active application; in 
  201. this example, it says:
  202.  
  203.     000910   0D54D 6163 4472  6177  2031  2E35  8100  .MacDraw 1.9.5..
  204.  
  205. "00910" tells you what memory location this is; ".MacDraw 1.9.5.." tells you what 
  206. application is active (for example, you may have crashed when trying to switch between 
  207. applications in MultiFinder; this can help you determine which application crashed).    DM 
  208. can be used to display many memory locations other than 910 (which is a system global); 
  209. other system globals are listed on pages 481-488 of Scott Knaster's book, How to Write 
  210. Software for a Macintosh.
  211.  
  212.  
  213.             4.  IL PC-20 (instruction list, starting 20 bytes before the program counter address) 
  214.  
  215.     This command disassembles (i.e. translates) assembly code into something readable 
  216. - if you read 68000 code!  It can be helpful to the programmers to look at this, and you 
  217. may be able to learn it through osmosis.  You can disassemble any number of lines and 
  218. from any address.
  219.  
  220.     The address is the value right after IL; in this case it's "PC", which has the value of 
  221. 261C1C because that's where the Program Counter is (see above).  You could use the 
  222. actual value " 261C1C", as in "IL 261C1C-20", but it's usually easier to type PC than 
  223. figure out its location and type that in.  
  224.  
  225.     The number of bytes is your choice; it indicates how many bytes before the 
  226. program counter MacsBug should begin disassembling.  In general, the program counter is 
  227. not shown at exactly the right place, so if you look back a few lines from the PC you are 
  228. more likely to discover the correct line.  This is because the program counter is sometimes 
  229. advanced before the previous instruction was completed; if the Mac crashes on an 
  230. instruction after advancing the program counter, the program counter is in the wrong place.  
  231. That's why you need to look at 10 or 20 bytes before the PC.  Note:  MacsBug displays 14 
  232. lines of disassembled code at once.  If you press return, MacsBug will give you the next 
  233. 14 lines; you can do this over and over to go through a long instruction list. (Normally, 
  234. when you press return, MacsBug repeats your last command exactly; this is one of the few 
  235. cases where pressing return gives you additional information instead of repeating the last 
  236. information it gave. )  Another thing to notice is how the addresses are listed:  they are all 
  237. even numbers.  This is because the instructions for the 68000 chip are an even number of 
  238. bytes, and they should always start at an even number.  If you notice that the address for 
  239. the PC is an odd address, you probably crashed with an address error (it couldn't do 
  240. anything at that address).
  241.  
  242.  
  243.             5.  HC (Heap Check)
  244.  
  245.     Heap check tells you the location of the current heap. It's a good idea to do this as 
  246. soon as you drop into MacsBug, so that you will know if your heap is corrupted.  If the 
  247. heap is ok (i.e. not trashed or corrupted), MacsBug will say something like "Current heap 
  248. is at 001CE8AA."  If the heap is corrupted, MacsBug says something like "Heap?  
  249. @0001BE0A  00427076"  (this is an imaginary heap location, just used for example.)  The 
  250. question mark after Heap indicates that the heap has been corrupted.  If the heap is not ok, 
  251. Do Not Use Any Heap Command Other Than HX if you have a bad heap (HX 
  252. exchanges you away to another heap; for more info, see below).  If you try to get a heap 
  253. dump or heap total from a bad heap, you may cause your machine to be rebooted or create 
  254. an address error - and then any useful information you were trying to get out of the 
  255. MacsBug session will be lost!  You can use HC at any point to see what heap you are 
  256. currently set to.
  257.  
  258.  
  259.             6.  HT (Heap Total)
  260.  
  261.     HT will get you information on the status of the memory within the current heap.  
  262. When you dropped into MacsBug above, the current heap was the application heap (for 
  263. MacDraw).  To check that you are still looking at this heap, type HC; if the heap address 
  264. isn't  1600 (on an SE, or 1400 on a Mac+, or 1E00 on a MacII - these are the locations of 
  265. the system heap on each machine), then you are in the application heap (see "A Discussion 
  266. of Heaps", below, for more information on system and application heaps.) Then type HT; 
  267. it should look something like this:
  268.  
  269.     Current heap is at 001CE8AA
  270.  
  271.     Ptrs: 0003  Hand: 0045  Locked: 0003  Purgeable: 0007
  272.  
  273.     Heap Sze: 0002C636 Free: 0001C09C Purge Sp: 00003014
  274.  
  275. This tells you:
  276.  
  277.     • the location of the heap (1CE8AA)
  278.  
  279.     • the number of pointers (there are 3 pointers in this heap)
  280.  
  281.     • the number of handles (45 is hex for 69, so there are 69 handles in this heap)
  282.  
  283.     • the number of locked blocks in the heap (3)
  284.  
  285.     • the number of purgeable blocks (7)
  286.  
  287.     • the size of the heap (2C636 hex bytes)
  288.  
  289.     • the amount of free space (1C09C is hex for 114844, which is about 112K)
  290.  
  291.     • the amount of purgeable space (3014 is hex for 12308, which is about 12K)
  292.  
  293. When you have little free or purgeable space, you may have crashed because you ran out of 
  294. memory; use HT to give you a better idea of how tight memory was.  (Note:  see below 
  295. "CV", for information about converting hex numbers to decimal.)
  296.  
  297.  
  298. WARNING:  Do not use HT when the heap may be corrupted; first, type HC to see that it 
  299. is ok.  If you don't get a question mark, it's probably ok to get a heap total or a heap 
  300. dump.
  301.  
  302.  
  303.             7.  HX (Heap eXchange)
  304.  
  305.     HX stands for Heap eXchange; it lets you switch around between the various heaps.  
  306. For a more in depth explanation of heaps, including how to look at the MultiFinder 
  307. (Juggler) heap, see "A discussion of heaps", below.  You can use HX to toggle between 
  308. the two primary heaps:  the current application heap and the system heap.  When you drop 
  309. into MacsBug, you are usually in the application heap; if you type HX, you will exchange 
  310. to the system heap.  If you type HX again, you will exchange back to the application heap.  
  311. You can always use HC to check which heap you are in, and whether or not the heap has 
  312. been corrupted.  You can exchange to other heaps such as the MultiFinder heap or any of 
  313. the applications within the MultiFinder heap; this is covered in depth below.
  314.  
  315.  
  316.             8.  HD (Heap Display)  
  317.  
  318.                     This command displays the current heap.  A heap display looks like this:
  319.  
  320.     >HD                
  321.  
  322.     0001C3A0 h 0000000C    00269E60    02F2 CDEF 0101
  323.  
  324.     0001C3AC h 00000046    00269E9C    02F2 DITL 0103
  325.  
  326.     0001C3F2 h 0000000E p  00269E98    02F2 STR# 0100 (see ex. below)
  327.  
  328.     0001C400 h 000002D0    00269E90    02F2 DITL 0105
  329.  
  330.     0001C6D0 h 000002D0    00269E58    02F2 CNTL 0100
  331.  
  332.     0001C9A0 h 00000092    00269E54    02F2 MENU 0400
  333.  
  334.     0001CA32 h 0000000C    00269E50    02F2 MENU 0700
  335.  
  336.     0001CA3E h 0000000C    00269E4C    02F2 MENU 0800
  337.  
  338.     0001CA4A h 0000000C    00269E48    02F2 MENU 0600
  339.  
  340.     0001CA56 h 0000000C    00269E44    02F2 MENU 0300
  341.  
  342.     0001CA62 h 000002D0    00269E3C    02F2 MENU 0A00
  343.  
  344.     0001CD32 h 00000092    00269E38    02F2 MENU 0500
  345.  
  346.     0001CDC4 h 0000000C    00269E34    02F2 MENU 0200
  347.  
  348.     0001CDD0 h 0000000C    00269E30
  349.  
  350.     0001CDDC h 0000000C    00269E2C    02F2 CURS 010E
  351.  
  352.     0001CDE8 h 0000000C  p 00269E28    02F2 fcod 00FD
  353.  
  354.     0001CDF4 h 0000001C  p 00269E68    02F2 fcod 00FB
  355.  
  356.     0001CE10 h 00000012    00269EA8
  357.  
  358.     
  359.  
  360.                 
  361.  
  362. Each line of the display contains information about a block in the current heap zone.  The 
  363. columns contain the following information (the line used for the example is the third line 
  364. in the display above; the numbers above each column refer to the names listed below):
  365.  
  366.  
  367.     1    2    3    4    5    6    7    8    9 
  368.  
  369. 0001C3F2  h   0000000E  p    00269E98  (*)      02F2   STR#  0100
  370.  
  371.  
  372.  
  373. 1:  Block address (0001C3F2)
  374.  
  375. 2:  Type (h)      
  376.  
  377. 3:  Size  (0000000E)       
  378.  
  379. 4:  Flag  (p)
  380.  
  381. 5:  Master pointer location  (00269E98)
  382.  
  383. 6:  Locked (*) 
  384.  
  385. 7:  Refnum (02F2)
  386.  
  387. 8:  Res type (STR#)
  388.  
  389. 9:  ID# (0100)             
  390.  
  391.  
  392.  
  393. Block address points to the start of the block of memory.  The first 8 bytes of each 
  394. block is the header, which is used for the memory manager, so that space doesn't contain 
  395. information you are likely to be interested in.  This means that you have to account for 
  396. that space when you are looking at the block; more about this later, in the section about 
  397. the MultiFinder heap.
  398.  
  399.  
  400. Type is one of three letters, indicating:
  401.  
  402.     f  - free block
  403.  
  404.     p - pointer
  405.  
  406.     h - handle to a relocatable block.
  407.  
  408.  
  409. Size is the physical size of the block, in hex; the size includes the contents of the block, 
  410. the header, and any unused bytes at the end of the block.
  411.  
  412.  
  413. Flag - this column is used when the type column contains an h (for handle).  If there is a 
  414. p in the flag column, then the handle is purgeable.  If there is no p, then this handle is not 
  415. purgeable.  Note:  pointers are not purgeable, so there is never a "p" flag for a pointer 
  416. block.
  417.  
  418.  
  419. The master pointer location is used when the block is a handle.  The master pointer 
  420. location is the address of the master pointer block (which is usually in a non-relocatable 
  421. block).  You can use this to find the block by dereferencing it, which means using an @ 
  422. at the front of the address.  Again, more about this later, in the section on MultiFinder 
  423. heaps.
  424.  
  425.  
  426. An asterisk in the 6th column indicates that this block is locked;  if there is no asterisk, 
  427. then the block isn't locked (this is only used with non-purgeable blocks that are handles).  
  428. An unlocked block can be relocated, and a locked block can't.  Note:  pointers blocks are 
  429. always non-purgeable and locked, by definition:  you don't want to relocate a pointer.  
  430. Because pointers are always locked, MacsBug does not include an asterisk in the sixth 
  431. column; it might be considered redundant. Conclusion: when you see an asterisk in the 
  432. sizth column, you know that you are looking at a non-purgeable, non-relocatable handle 
  433. block.
  434.  
  435.  
  436. The last three columns are used when a block is a resource file block.  They are the 
  437. resource file's reference number (file refnum), its ID number, and the resource 
  438. type.
  439.  
  440.  
  441. You can terminate or interrupt a heap dump by pressing the backspace key; you can pause 
  442. it and restart it by pressing the space key.
  443.  
  444.  
  445.             9.  CV (ConVert)
  446.  
  447.     CV means ConVert; MacsBug will convert any value into unsigned hexidecimal, 
  448. signed hexidecimal, decimal, and binary for you.  This is very useful in checking sizes, 
  449. which are generally expressed in hex.  For example, if you type "CV 151515", MacsBug 
  450. returns:
  451.  
  452.    $00151515 00151515 #1381653 '....' 00000000 00010101 00010101 00010101
  453.  
  454. The first number, preceeded by $, is the unsigned hex representation; the second number is 
  455. the signed hex representation.  The third number, preceeded by #, is the decimal 
  456. representation; the 0's and 1's at the end are, of course, binary.  The section in the middle, 
  457. '....', is the text version, i.e. the ASCII representation (this number does not have an 
  458. ASCII equivalent.)  You can also get it to convert text to an ASCII code, or vice versa.  For 
  459. example, "CV 'M" (preceed the text you want to convert with an apostrophe) would get 
  460. you:
  461.  
  462.    $0000004D 0000004D  #77 '...M' 00000000 00000000  00000000  01001101
  463.  
  464. This shows that the ASCII code for M is 77 (the decimal version, since the ASCII chart is 
  465. written in decimal, not hex or binary.)  See if you can spell your name in ASCII 
  466. equivalents!   The Macintosh character set, which includes both the ASCII character set and 
  467. some special characters, can be found on page 247 of volume one of Inside Mac; a copy is 
  468. attached to the end of this document.
  469.  
  470.  
  471.             10.  TD (Total Display)
  472.  
  473.     As mentioned above, this allows you to see the total display.  This is usually 
  474. displayed when you first enter MacsBug, but it may scroll off.  You can get it back again 
  475. by typing TD.
  476.  
  477.  
  478.             11.  DV (Display Version)
  479.  
  480.     Display Version simply tells you which version of MacsBug you are using; you 
  481. should be using Macsbug 5.5 June 17th, 1987 or later.
  482.  
  483.  
  484.             12.  G (G0)
  485.  
  486.     Go can be used to return you to the point you were at when you dropped into 
  487. Macsbug.  For this tutorial session, you dropped into Macsbug by pressing the interrupt 
  488. switch; this means that there probably wasn't anything wrong with your system, and if you 
  489. return to where you left off, you can continue to work.  HOWEVER, if you crashed into 
  490. Macsbug or were hung and interrupted into it, your Mac is probably not in a workable 
  491. state.  If you use G at this point, you may crash again, it may hang, it may reboot...  To be 
  492. safe, only use this command when you know the machine is "clean".
  493.  
  494.  
  495.             13.  RB (ReBoot)
  496.  
  497.     You can always reboot from Macsbug - which you will often need to do when the 
  498. machine is really messed up and you've had an address or bus error.  When you need to 
  499. reboot, you can do so by using this command, the restart switch on the programmer's 
  500. button, or the power switch.
  501.  
  502.  
  503.             14.  ES (Escape Shell)
  504.  
  505.     Sometimes, your application heap may be messed up, but other things are still 
  506. running ok.  If you type ES, the Mac will attempt to return to the Finder (after quitting the 
  507. application you were in).  This may allow you to go into other applications and save data.  
  508. However, anytime you've been forcefully dropped into Macsbug, you must restart the 
  509. system before doing any serious work, because there may be other unknown conditions in 
  510. the machine.  So use ES to get back to the Finder (when possible), clean things up, save 
  511. what you can, and restart to try again.  It is extremely important that you reboot after using 
  512. ES and before continuing with your testing, or your results will be invalid.
  513.  
  514.  
  515.             15.  ` (toggle between screen and MacsBug)
  516.  
  517.     This strange key, the back apostrophe, lets you toggle between looking at the 
  518. Macsbug screen and at the Mac screen as it was just before you crashed.  This sometimes 
  519. lets you get an idea of what was happening when you crashed.
  520.  
  521.  
  522.     V.  A discussion of heaps
  523.  
  524.     The Macintosh divides memory up into a number of heaps, each of which has a different 
  525. function.  Before MultiFinder, there were only two heaps:  the application heap and the 
  526. system heap.  The application heap contains the application's code and its resources, and the 
  527. system heap contains operating system data structures.  
  528.  
  529.     You can look at both of these heaps in Macsbug, and can toggle between them by typing 
  530. HX, or heap exchange.  When you drop into MacsBug, you are set at the application heap; if 
  531. you type HC for heap check, MacsBug will tell you about the application heap.  When you type 
  532. HX you toggle (exchange) to the system heap (and if you type it again, you toggle back to the 
  533. application heap).  You can tell which heap you are looking at because the system heap begins at 
  534. a specific location for each machine:
  535.  
  536.         On the Mac+, it begins at 1400.
  537.  
  538.         On the SE, it begins at 1600;
  539.  
  540.         On the Mac II, it begins at 1E00; 
  541.  
  542.  
  543.     If the heap starts at a location other than one of these, you are looking at an application 
  544. heap.  To see what the heap location is, type HC or HX; MacsBug will tell you the current heap 
  545. location (if the heap is not corrupted), i.e. "Current heap is at 00001600."
  546.  
  547.     The application heap contains the code and resources for your current application.  In this 
  548. example, the current application is MacDraw, because that is where you were when you pressed 
  549. the programmer's interrupt switch.  You can tell the name of the current application by typing 
  550. "DM 910"; this memory location holds a string containing the application's name.  If you were in 
  551. the Finder when you pressed the interrupt switch, the Finder would be the current application; 
  552. you would be looking at the Finder's heap when you dropped into MacsBug, and DM 910 
  553. would return "Finder".    
  554.  
  555.  
  556.  
  557.     VI.  The MultiFinder heap
  558.  
  559.     With MultiFinder, the heaps work differently.  You still have a system heap, and it still 
  560. starts at the standard location.  You also still have a current application heap, and you can toggle 
  561. between the two using HX.  The difference with MultiFinder is that you may have more than one 
  562. application loaded at once; although only one of these can be the current application, the other 
  563. applications have their own heaps.  You have to work a bit harder to get to them, but it is 
  564. possible to examine the heap for each application.
  565.  
  566.     When MultiFinder is running, it takes over the space previously used as the application 
  567. heap and uses it as its own heap.  It then subdivides this fairly large space into separate heaps for 
  568. each application.   
  569.  
  570.     To exchange to the MultiFinder heap, type "HX @@2A6+C."  ("@@2A6+C" refers to 
  571. the MultiFinder heap - that's the place you need to get to in order to look at the MultiFinder 
  572. heap.)  To make sure that the heap is ok, type HC before doing anything else.  (If you've 
  573. crashed while using MultiFinder, there's a chance that the MultiFinder heap is trashed.)  If the 
  574. heap is ok, you can display the heap by typing HD, and then look at the last few lines of the heap 
  575. to find the locations of the other application heaps.  In our example, we have MacWrite and 
  576. MacDraw loaded, and we dropped into MacsBug while MacDraw was the active (current) 
  577. application.  This means that when we use HX alone (i.e. without an address such as 
  578. "@@2A6+C"), we will switch back and forth between the system heap and the MacDraw heap.  
  579. In addition, there is a MultiFinder heap, and within the MultiFinder heap, a MacWrite heap.  As 
  580. a matter of fact, the MacDraw heap is also inside the MultiFinder heap.  And that's not all!  The 
  581. Finder has a heap inside the MultiFinder heap (this allows you to switch back to the Finder 
  582. whenever you want while you're running MultiFinder).  A few other small applications, such as 
  583. Backgrounder, also have small heaps; this makes it possible for you to print in the background 
  584. while you do other things in the foreground.
  585.  
  586.  
  587.     Let's look at the MultiFinder heap (this will only include the last lines of the heap display):
  588.  
  589.   
  590.  
  591.     >HX @@2A6+C               (exchange to the MultiFinder heap)
  592.  
  593.     Current heap is at 0026048
  594.  
  595.     >HC                         (make sure the MultiFinder heap is ok)
  596.  
  597.     Current heap is at 0026048
  598.  
  599.     >HD                       (display the MultiFinder heap -this shows 
  600.  
  601.                                 just the last screenful)
  602.  
  603.     0002665C h 00000012    0026A080
  604.  
  605.     0002666E h 0000000C    0026A078
  606.  
  607.     0002667A h 00000046    0026A0AC
  608.  
  609.     000266C0 h 0000000E    0026A0A8
  610.  
  611.     000266CE h 000002E8    0026A0A0
  612.  
  613.     000269B6 h 000002E8    0026A074
  614.  
  615.     00026C9E h 000000CE    0026A070
  616.  
  617.     00026D6C h 0000000C    0026A068
  618.  
  619.     00026D78 h 0000000C    0026A064
  620.  
  621.     00026D84 h 0000000C    0026A06C
  622.  
  623.     00026D90 h 00000012    0026A0B8
  624.  
  625.     00026DA2 h 000002E8    0026A058
  626.  
  627.     0002708A h 000000CE    0026A054
  628.  
  629.     00027158 h 0000000C    0026A050
  630.  
  631.     00027164 h 0000000C    0026A04C
  632.  
  633.     00027170 h 0000000C    0026A048
  634.  
  635.     0002717C f 001A770A
  636.  
  637.      001CAA1A h 00003E88    0026A044 *
  638.  
  639.     001CE8A2 h 00030008    0026A05C *
  640.  
  641.     001FE8AA h 00038008    0026A060 *
  642.  
  643.     002368B2 h 00028008    0026A08C *
  644.  
  645.     0025E8BA h 00002208    0026A0A4 *
  646.  
  647.     00260AC2 h 00000034    0026A0B0 *
  648.  
  649.     00260AF6 h 0000003A    0026A0B4 *
  650.  
  651.     00260B30 h 0000253A p  0026A0C0 *
  652.  
  653.     0026306A h 0000064A p  0026A0C4 *
  654.  
  655.     00169C1C p 000004B0             *
  656.  
  657.     Ptrs: 0002  Hand: 0021 Locked: 0009 Purgeable: 0000
  658.  
  659.     Heap Sze: 00244084 Free: 001A7726 Purge Sp: 00000000
  660.  
  661.    
  662.  
  663.     We can look at the last few lines of this display and learn a great deal about the various 
  664. applications which are loaded: the lines which are marked as handles (h's in the 2nd column), 
  665. not purgeable (p's in the 4th column), and locked (asterisks in the 6th column) are potential 
  666. application heaps.  Seven of the last ten lines meet these qualifications (each line represents a 
  667. block in memory).  We know that open applications include DA Handler (so that Alarm Clock 
  668. can be open), MacWrite, MacDraw, the Finder, and perhaps Backgrounder. (Note:  
  669. Backgrounder is a small application which sits around waiting for a print job to be spooled.  
  670. When a spooled file is present, Backgrounder launches PrintMonitor which can then print the file 
  671. in the background.)  The third column is the size, in hex; if we convert these sizes and then 
  672. divide by 1024, we see that, of the seven potential heaps, the top five lines (blocks) are sizes 
  673. 15.5K, 192K, 224K, 160K, and 16K, respectively (use the calculator to divide the number of 
  674. bytes by 1024, to get the number of K).   Before we launched MacDraw and MacWrite, we set 
  675. the size resources to 192K and 224K.  If you check the Finder, you will see that it likes to have 
  676. 160K for its heap.  The first one, 15.5K, is likely to be the DA Handler, and the last one, 8.5K, 
  677. is likely to be the Backgrounder heap.  Because these applications don't let you change their 
  678. resource sizes, you have to look at their size resources in ResEdit.  DA Handler 1.0 has a size 
  679. resource of 15.5K, and Backgrounder 5.0 has a size resource of 8.5K.  Thus, we can account 
  680. for the top five application heaps.  The last two, with sizes of 34 and 3A (in hex) are resident 
  681. whenever MultiFinder is running, but are of no interest to us.
  682.  
  683.     The best way to tell which application heap is which is to keep a list of the size resources 
  684. you set for each application, so that you can compare them to the heap sizes shown in MacsBug.  
  685. Try to set a unique size for each, to give your detective work a better chance to succeed.
  686.  
  687.     However, you can't take it for granted that if the heap size is about the same as the size 
  688. resource, you've found the right heap; you should look at it a bit more.  In order to examine the 
  689. actual application heaps, we use the HX command again, and specify an address.  How do we 
  690. know what address to look at?  From the explanation of heap displays (above), we know that the 
  691. first column is the block address, and that the address given includes the 8-byte header used for 
  692. the memory manager.  Therefore, if we use the block address and add 8 bytes, we'll get to the 
  693. beginning of the supposed application heap.
  694.  
  695.     Try it.  Refer to the previous pages for the entire MacsBug dump; only the necessary lines 
  696. will be included here. Compare what you see to what is shown in the document.  First, look at 
  697. the MacDraw heap.  This one will be easy to verify, because it is the current application heap, 
  698. and you know you can always get to it by typing HX one or two times.  Remember, MacDraw 
  699. has a size resource of 192K, which is 30008 bytes in hex.  Look at your MultiFinder heap 
  700. display, and find the line with an asterisk at the end, which has the number 30008 in the 3rd 
  701. column.  Take the number in the first column (in this case, the number in the first column is 
  702. 001CE8A2), and substitute it in these commands:
  703.  
  704.  
  705.     >HX 1CE8A2+8
  706.  
  707.     >HC
  708.  
  709.     Current Heap is at 001CE8AA
  710.  
  711.     >HX
  712.  
  713.     Current Heap is at 00001600        (that's the system heap on an SE)
  714.  
  715.     >HX
  716.  
  717.     Current Heap is at 001CE8AA
  718.  
  719.  
  720.     It works!  By adding 8 to the block address on the line you're interested in and 
  721. exchanging to that heap, you've found one of the application heaps.  Using HX twice made you 
  722. switch between the system heap and the application heap, and proved that the heap you're 
  723. looking at was the same application heap we'd been looking at earlier, MacDraw.  It's important 
  724. to type HC, to check that you've switched to a valid heap.
  725.  
  726.     Now try to look at the MacWrite heap.  First, you have to switch back to the MultiFinder 
  727. heap and dump it, so that you can look for the blocks which contain the other application heaps.  
  728. Next, find the line containing the size 38008, which is 224K, the size resource for MacWrite 
  729. (this block is underlined in the example below).  Add 8 to that, exchange to it, and check the 
  730. heap to make sure it's valid:
  731.  
  732.   
  733.  
  734.     >HX @@2A6+C               (exchange to the MultiFinder heap)
  735.  
  736.     Current heap is at 0026048
  737.  
  738.     >HC                         (make sure the MultiFinder heap is ok)
  739.  
  740.     Current heap is at 0026048
  741.  
  742.     >HD                       (display the MultiFinder heap -this shows 
  743.  
  744.                                 just the last screenful)
  745.  
  746.     0002665C h 00000012    0026A080
  747.  
  748.     0002666E h 0000000C    0026A078
  749.  
  750.     0002667A h 00000046    0026A0AC
  751.  
  752.     000266C0 h 0000000E    0026A0A8
  753.  
  754.     000266CE h 000002E8    0026A0A0
  755.  
  756.     000269B6 h 000002E8    0026A074
  757.  
  758.     00026C9E h 000000CE    0026A070
  759.  
  760.     00026D6C h 0000000C    0026A068
  761.  
  762.     00026D78 h 0000000C    0026A064
  763.  
  764.     00026D84 h 0000000C    0026A06C
  765.  
  766.     00026D90 h 00000012    0026A0B8
  767.  
  768.     00026DA2 h 000002E8    0026A058
  769.  
  770.     0002708A h 000000CE    0026A054
  771.  
  772.     00027158 h 0000000C    0026A050
  773.  
  774.     00027164 h 0000000C    0026A04C
  775.  
  776.     00027170 h 0000000C    0026A048
  777.  
  778.     0002717C f 001A770A    
  779.  
  780.     001CAA1A h 00003E88    0026A044 *
  781.  
  782.     001CE8A2 h 00030008    0026A05C *
  783.  
  784.     001FE8AA h 00038008    0026A060 *
  785.  
  786.     002368B2 h 00028008    0026A08C *
  787.  
  788.     0025E8BA h 00002208    0026A0A4 *
  789.  
  790.     00260AC2 h 00000034    0026A0B0 *
  791.  
  792.     00260AF6 h 0000003A    0026A0B4 *
  793.  
  794.     00260B30 h 0000253A p  0026A0C0 *
  795.  
  796.     0026306A h 0000064A p  0026A0C4 *
  797.  
  798.     00169C1C p 000004B0             *
  799.  
  800.     Ptrs: 0002  Hand: 0021 Locked: 0009 Purgeable: 0000
  801.  
  802.     Heap Sze: 00244084 Free: 001A7726 Purge Sp: 00000000
  803.  
  804.     >HX 1FE8AA+8
  805.  
  806.     Current heap is at 001FE8B2
  807.  
  808.     >HC
  809.  
  810.     Current heap is at 001FE8B2
  811.  
  812.      
  813.  
  814.     This is more than likely the MacWrite heap; there isn't much more you can do to verify 
  815. this, however, without learning a great deal more about MacsBug and assembly language.  It is 
  816. still useful to be able to exchange to all of the applications heaps and check that they are not 
  817. corrupted.  Another thing you can do is display memory for the size of the heap and see if it 
  818. contains any recognizable character strings.  To do this, you look again at the block and its size 
  819. as listed in the MultiFinder heap, and use the DM command.  The format is "DM  (block 
  820. address+8)  (Size-8)."  This means "display what's in memory at the beginning of the 
  821. application heap (accounting for the 8-byte header) for an amount equal to the size of the 
  822. application heap, minus the 8-byte header".  Remember that you can use the space bar to pause 
  823. and continue scrolling.  Try it, using the correct block address from your MultiFinder heap:
  824.  
  825.  
  826.     >DM 1FE8AA+8 38008-8
  827.  
  828.  
  829.     You can also use the DM command to look at DAs.  The DA Handler is an application 
  830. which is loaded into the MultiFinder heap, but the DAs themselves are drivers which are loaded 
  831. in the system heap.  To look for a DA, you switch to the system heap, dump a list of the drivers, 
  832. and then display the first bytes of the driver:
  833.  
  834.     >HX
  835.  
  836.     Current Heap is at 001CE8AA    (the MacDraw heap)
  837.  
  838.     >HX
  839.  
  840.     Current Heap is at 00001600       (the system heap on an SE)
  841.  
  842.     >HD 'DRVR                    (dump the drivers in this heap)
  843.  
  844.     Current heap is at 00001600
  845.  
  846.     00018170 h 00000F7E p 0000D944  0002 DRVR 000D
  847.  
  848.     Cnt ### 0001 0000349C
  849.  
  850.     >DM 18170 F7E
  851.  
  852.  
  853.     "HD 'DRVR" tells MacsBug to give you a list of all the drivers in the system heap.  Each 
  854. DA has its own drivers; other drivers may also be included.  The command "DM 18170 F7E" 
  855. tells MacsBug to display memory starting at the address of the driver for the entire size of the 
  856. driver.  Usually, the driver's name is included in the first two or three lines; use the space bar to 
  857. stop the scrolling display, and the delete key to exit the command.  If you have other drivers 
  858. listed, you can look at them also.  It is sometimes helpful to be able to find out what DAs were 
  859. loaded when you have crashed and can't remember what you had open.
  860.  
  861.         
  862.  
  863.  
  864.     VII.  What to write down in your bug report
  865.  
  866.     This tutorial has covered a lot of commands; how can you use this information in your 
  867. bug reports?  The engineer on your project will have his or her own needs for specific 
  868. information; have your team leader find out what they are, and include that information in your 
  869. report.  
  870.  
  871.  
  872. Here is a general list; include both the commands and the results in your report:
  873.  
  874.         1.   HC - report the heap location and its condition
  875.  
  876.         2.   HX - exchange to the other heap
  877.  
  878.         3.   HC - report the location of the other heap and its condition
  879.  
  880.         4.   DM 910 - report the current application
  881.  
  882.         5.   PC - the address of the PC
  883.  
  884.         6.   WH PC - the previous named routine
  885.  
  886.         7.   IL PC-20 - if you have time and room, write down the lines preceeding and following the 
  887. PC
  888.  
  889.         8.   DM RA7 30 - Display the first 30 bytes of the stack
  890.  
  891.         9.   TD - write down the information from the total display, including the lines for RA6 and RA7
  892.  
  893.         10.  HX @@2A6+C - if you're running under MultiFinder
  894.  
  895.         11.  HC - report how the MultiFinder heap is
  896.  
  897.         12.  Look at other application heaps and their condition
  898.  
  899.         13.  HT - check the amount of free and purgeable space for each heap you examine
  900.  
  901.     
  902.  
  903.     VIII.  Other sources of information on MacsBug
  904.  
  905.     1.  Appendix D, How to Write Software for the Macintosh, Scott Knaster.
  906.  
  907.     2.  Debugging with MacsBug (chapter 8), MPW manual, Apple Computer.
  908.